﻿using Microsoft.AspNetCore.Http;
using SBlogCore.Application.UploadFileManager.IServices;

namespace SBlogCore.Application.UploadFileManager.Controllers
{
    /// <summary>
    /// 文件上传
    /// </summary>
    public class UploadFileController : AuthorizeBaseController
    {
        private readonly IUploadFileService _uploadFileService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="uploadFileService"></param>
        public UploadFileController(
            IUploadFileService uploadFileService
            )
        {
            this._uploadFileService = uploadFileService;
        }
        /// <summary>
        ///上传文件
        /// </summary>
        /// <param name="fileList"></param>
        /// <returns></returns>
        [HttpPost]
        [RequestSizeLimit(200_000_000)] //最大200m左右
        public async Task<List<string>> UploadFile(IFormFileCollection fileList)
        {
            if (fileList.Count == 0)
                throw SBlogCoreException.Say("文件数量不能为0");
            var taskList = await _uploadFileService.SaveMoreFile(fileList.ToList());
            return taskList;
        }
    }
}
